#include<bits/stdc++.h>
using namespace std;
int n,m,a[100005],c[100005],T,x[100005],k1,k2,k3,b[5]={0,5,19,7,1};
int main(){
 freopen("arena.in","r",stdin);
 freopen("arena.out","w",stdout);
 cin>>n>>m;
 for(int i=1;i<=n;i++){
  cin>>a[i];
 }
 for(int i=1;i<=m;i++){
  cin>>c[i];
 }
 cin>>k1>>k2>>k3;
 cin>>T;
 for(int i=1;i<=T;i++){
  for(int i=1;i<=n;i++){
   cin>>x[i];
  }
  cout<<b[i]<<endl;
 }
 return 0;
}
